package com.ruoyi.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camp.domain.CCampsite;
import com.ruoyi.camp.service.ICCampsiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地营位功能Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/camp/campsite")
public class CCampsiteController extends BaseController
{
    @Autowired
    private ICCampsiteService cCampsiteService;

    /**
     * 查询营地营位功能列表
     */
    @PreAuthorize("@ss.hasPermi('camp:campsite:list')")
    @GetMapping("/list")
    public TableDataInfo list(CCampsite cCampsite)
    {
        startPage();
        List<CCampsite> list = cCampsiteService.selectCCampsiteList(cCampsite);
        return getDataTable(list);
    }

    /**
     * 导出营地营位功能列表
     */
    @PreAuthorize("@ss.hasPermi('camp:campsite:export')")
    @Log(title = "营地营位功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CCampsite cCampsite)
    {
        List<CCampsite> list = cCampsiteService.selectCCampsiteList(cCampsite);
        ExcelUtil<CCampsite> util = new ExcelUtil<CCampsite>(CCampsite.class);
        util.exportExcel(response, list, "营地营位功能数据");
    }

    /**
     * 获取营地营位功能详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:campsite:query')")
    @GetMapping(value = "/{campsiteId}")
    public AjaxResult getInfo(@PathVariable("campsiteId") String campsiteId)
    {
        return success(cCampsiteService.selectCCampsiteByCampsiteId(campsiteId));
    }

    /**
     * 新增营地营位功能
     */
    @PreAuthorize("@ss.hasPermi('camp:campsite:add')")
    @Log(title = "营地营位功能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CCampsite[] cCampsite)
    {
        return toAjax(cCampsiteService.insertCCampsite(cCampsite));
    }

    /**
     * 修改营地营位功能
     */
    @PreAuthorize("@ss.hasPermi('camp:campsite:edit')")
    @Log(title = "营地营位功能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CCampsite cCampsite)
    {
        return toAjax(cCampsiteService.updateCCampsite(cCampsite));
    }

    /**
     * 删除营地营位功能
     */
    @PreAuthorize("@ss.hasPermi('camp:campsite:remove')")
    @Log(title = "营地营位功能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{campsiteIds}")
    public AjaxResult remove(@PathVariable String[] campsiteIds)
    {
        return toAjax(cCampsiteService.deleteCCampsiteByCampsiteIds(campsiteIds));
    }
}
